package com.fw.util;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class DateUtils {

    public static final Date getCurrentDate() {
	Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
	return new Date(calendar.getTime().getTime());
    }

    public static final Date getFromDate(Date date) {
	Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
	calendar.setTime(date);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.MILLISECOND, 0);
	return calendar.getTime();
    }

    public static final Date getToDate(Date date) {
	Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
	calendar.setTime(date);
	calendar.set(Calendar.HOUR_OF_DAY, 23);
	calendar.set(Calendar.MINUTE, 59);
	calendar.set(Calendar.SECOND, 59);
	calendar.set(Calendar.MILLISECOND, 99);
	return calendar.getTime();
    }

    public static final Long diffDays(Date startDate, Date endDate) {
	long diffDays = 0;
	// in milliseconds
	if (startDate != null && endDate != null) {
	    long diff = endDate.getTime() - startDate.getTime();
	    diffDays = diff / (24 * 60 * 60 * 1000);
	}
	return diffDays;
    }
}
